package edu.chinasoft.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.annotation.WebServlet;
import org.apache.log4j.Logger;

import edu.chinasoft.pojo.User;
import edu.chinasoft.service.UserService;
import edu.chinasoft.service.UserServiceImp;

/**
 *
 * @author mhao
 * @date 2020年2月12日:下午3:56:48
 * @version V1.0
 * @Description: 
*/
@WebServlet(name = "myupdateUserFlagforServlet", value = "/servlet/updateuserflagforservlet")
public class updateUserFlagforServlet extends HttpServlet {
	private static Logger logger = Logger.getLogger(updateUserFlagforServlet.class);
	private UserService userService = new UserServiceImp();
	/**
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		logger.debug(" Servelt01 >doGet start.......");
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		//获取所要更新用户的id和状态
		String idString = request.getParameter("id");
		String userFlag = request.getParameter("user_flag");
		User user = new User();
		user.setId(Integer.parseInt(idString));
		user.setUserFlag(userFlag);
		boolean result = userService.modifyUserInfo(user);
		//如果更新失败，显示失败页面
		if(result) {
			response.sendRedirect(""+request.getContextPath()+"/servlet/finduserpageforservlet");
		}else {
			response.sendRedirect(""+request.getContextPath()+"/updateusererror.jsp");
		}
		logger.debug(" Servelt01 >doGet end.......");
	}

	/**
	 *
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		logger.debug(" Servelt01 >doPost start.......");
		this.doGet(request, response);
		logger.debug(" Servelt01 >doPost end.......");
	}

}